package net.butfly.albacore.dao;

import java.io.Serializable;

import net.butfly.albacore.dbo.criteria.Criteria;
import net.butfly.albacore.dbo.criteria.Page;
import net.butfly.albacore.entity.Entity;
import net.butfly.albacore.entity.EntityStub;
import net.butfly.albacore.utils.GenericUtils;

@Deprecated
public abstract class GenericDAOBase<E extends Entity<K>, K extends Serializable> extends EntityDAOBase implements
		GenericDAO<E, K> {
	private static final long serialVersionUID = 1L;
	protected Class<E> entityClass = this.getEntityClass();

	protected abstract EntityStub<K> getCurrentOPStub();

	@SuppressWarnings("unchecked")
	private Class<E> getEntityClass() {
		return (Class<E>) GenericUtils.getGenericParamClass(this.getClass(), GenericDAOBase.class, "E");
	}

	@Override
	public void delete(K id) {
		super.delete(this.getEntityClass(), id);
	}

	@Override
	public K[] selectID(Criteria criteria, Class<K> clazz) {
		return super.getKeyPage(entityClass, DAOContext.COUNT_STATMENT_ID, DAOContext.SELECT_STATMENT_ID,
				criteria.getParameters(), Page.ALL_RECORD);
	}

	@Override
	public void delete(Criteria criteria) {
		super.delete(this.getEntityClass(), criteria);
	}

	@Override
	public E load(K id) {
		return super.select(this.getEntityClass(), id);
	}

	@Override
	public E[] select(Criteria criteria) {
		return super.select(this.getEntityClass(), criteria, Page.ALL_RECORD);
	}

	@Override
	public int count(Criteria criteria) {
		return super.count(this.getEntityClass(), criteria);
	}
}
